package org.andao.commons.taglib.ui;

import java.io.IOException;

import javax.servlet.http.HttpSession;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;

import org.andao.commons.cache.CacheAppManager;
import org.andao.commons.taglib.BaseTagSupport;
import org.andao.core.config.ConfigPropertyReader;
import org.andao.core.config.Constants;
import org.andao.core.utils.ExDateUtils;
import org.andao.core.utils.ExStringUtils;



/**
 * 系统信息.
 * 
 * @author Marco.hu(hzg139@163.com)
 */
public class SystemInfoTag extends BaseTagSupport{

	private static final long serialVersionUID = -5691859415960521309L;
	
	private String isPrintVersion = Constants.BOOLEAN_YES;//是否输出版本
	
	private String isOnlyAppInfo = Constants.BOOLEAN_NO;//只输入AAP信息
	
	public int doEndTag() throws JspException {
		StringBuffer bf = new StringBuffer();
		
		if(isOnlyAppInfo.equals(Constants.BOOLEAN_YES)){
			bf.append(getAppInfo());
		}else{
			bf.append("Copyright © ");
			bf.append(ExDateUtils.getCurrentYear());
			//获取软件信息
		
			bf.append(" " +getAppInfo() + " ");			
			bf.append(" All Rights Reserved ");
			// 版本信息
			bf.append("<span style='margin-left:12px'></span> V:"+ConfigPropertyReader.getInstance().getProperty("seewo.edu.version"));
			bf.append(" (update:"+ ConfigPropertyReader.getInstance().getProperty("version.buildingdate")+" )");
			HttpSession session = getrequest().getSession(false);
			String[] hostArr = session.getId().split("\\.");
			if(null != hostArr && hostArr.length>1){
				bf.append(" @ "+hostArr[1]);
			}
		}
					
		JspWriter writer = this.pageContext.getOut();
		try {
			writer.append(bf.toString());
		} catch (IOException e) {
		   logger.error("获取版本信息出错：{}",e.fillInStackTrace());
		}
		return EVAL_PAGE;
	}

	private String getAppInfo(){
		if(ExStringUtils.isNotBlank(CacheAppManager.getSysConfigurationByCode("web.app.name").getParamValue())){
			return CacheAppManager.getSysConfigurationByCode("web.app.name").getParamValue();
		}
		return "";
	}
	
	public String getIsPrintVersion() {
		return isPrintVersion;
	}

	public void setIsPrintVersion(String isPrintVersion) {
		this.isPrintVersion = isPrintVersion;
	}

	public String getIsOnlyAppInfo() {
		return isOnlyAppInfo;
	}

	public void setIsOnlyAppInfo(String isOnlyAppInfo) {
		this.isOnlyAppInfo = isOnlyAppInfo;
	}
	
	

}
